package com.yc.auction.dao;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 访问数据库的方法
 * @author Administrator
 *
 */
public class DBAccess {
	public SqlSession getSqlSession() throws IOException{
		//读取配置我呢见获取数据库的连接信息
		Reader reader=Resources.getResourceAsReader("mybatis-config.xml");
		
		//通过配置信息构建一个SqlSessionFactory
		SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(reader);
		
		//通过构建的sql会话工程，打开一个数据库会话
		SqlSession session=factory.openSession();
	
		return session;
	}
}
